﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Mail;
using System.Web;
using Symbonix.NorSoNet.Communication.DAL.Repositories;

namespace Symbonix.NorSoNet.Communication.BLL.Friendship
{
    public class Workflow
    {
        public Symbonix.NorSoNet.Communication.BLL.Options.FriendRequestStatus SendFriendRequest(int fromUserId,int toUserId)
        {
            
            try
            {
                FriendDataRepository frRep = new FriendDataRepository();
                if (frRep.IsFriend(fromUserId, toUserId))
                {
                    return Symbonix.NorSoNet.Communication.BLL.Options.FriendRequestStatus.AlreadyFriends;
                }

                FriendData friend = new FriendData();
                friend.RequestedOn = DateTime.Now;
                friend.RequestedUserID = fromUserId;
                friend.RequestingUserID = toUserId;
                friend.Status = (int)Symbonix.NorSoNet.Communication.BLL.Options.FriendShipStatus.Requestpending;
                friend=frRep.Insert(friend);

                if (friend == null)
                    return Symbonix.NorSoNet.Communication.BLL.Options.FriendRequestStatus.Failed;

                SecurityMailHelper mailHelper = SecurityMailHelper.GetInstance();

                
                //mailHelper.SendRegistrationMail(user);

                return Symbonix.NorSoNet.Communication.BLL.Options.FriendRequestStatus.Success;

            }
            catch (SmtpException ex)
            {
                return Symbonix.NorSoNet.Communication.BLL.Options.FriendRequestStatus.MailSendFailed;
                //return Symbonix.NorSoNet.Security.BLL.Options.RegistrationCompleteStatus.MailSendFailed;
            }
            catch (Exception ex)
            {
                return Symbonix.NorSoNet.Communication.BLL.Options.FriendRequestStatus.ServerError;
                //if (status == MembershipCreateStatus.DuplicateEmail)
                //    return Symbonix.NorSoNet.Security.BLL.Options.RegistrationCompleteStatus.DuplicateEmail;
                //else if (status == MembershipCreateStatus.DuplicateUserName)
                //    return Symbonix.NorSoNet.Security.BLL.Options.RegistrationCompleteStatus.DuplicateUsername;
                //else if (status == MembershipCreateStatus.InvalidPassword)
                //    return Symbonix.NorSoNet.Security.BLL.Options.RegistrationCompleteStatus.InvalidPassword;
                //else if (status == MembershipCreateStatus.InvalidEmail)
                //    return Symbonix.NorSoNet.Security.BLL.Options.RegistrationCompleteStatus.InvalidEmail;
                //else if (status == MembershipCreateStatus.InvalidUserName)
                //    return Symbonix.NorSoNet.Security.BLL.Options.RegistrationCompleteStatus.InvalidUsername;
                //else if (status == MembershipCreateStatus.ProviderError)
                //    return Symbonix.NorSoNet.Security.BLL.Options.RegistrationCompleteStatus.ServerError;
                //else
                //    return Symbonix.NorSoNet.Security.BLL.Options.RegistrationCompleteStatus.ServerError;
            }
        }

       
    }
}
